#!/usr/bin/env python3
# vim: set ts=4 sw=4 fileencoding=utf-8:
# Luomio <nohappiness@gmail.com>
# Filename: dde-first-run.py
# Create Date: 27-03, 13

from os import path, remove
import locale
import os
import shutil
import getpass
import re
import subprocess

def querySystemType():
    f = open("/etc/deepin-version", "r")
    content = f.read()

    r = re.search(r"^Type=(.*)$", content, re.M)

    return r.group(1)

if __name__ == "__main__":
    lang, charset = locale.getdefaultlocale()
    sys_type = querySystemType()

    subprocess.Popen("/usr/bin/gxde-introduction")

    # create symlink for introduction video
    introduction_video_path = "/usr/share/gxde-introduction/demo.mp4"
    if path.exists(introduction_video_path):
        os.symlink(introduction_video_path, path.expanduser('~/Videos/gxde-introduction.mp4'))

    if sys_type != "Desktop":
        desktops = ['dde-computer.desktop', 'dde-trash.desktop']
        desktop_path = path.expanduser("~/Desktop")
        if not path.exists(desktop_path):
            os.makedirs(desktop_path)
        for desktop in desktops:
            desktop_file = path.join("/usr/share/applications", desktop)
            if path.exists(desktop_file):
                shutil.copyfile(desktop_file, path.join(desktop_path, desktop))

    if path.exists(path.expanduser('~/.config/autostart/dde-first-run.desktop')):
        remove(path.expanduser('~/.config/autostart/dde-first-run.desktop'))
